package org.devocean.groupbuying.web.frontend.displaybeans;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.devocean.groupbuying.domain.Article;
import org.devocean.groupbuying.domain.Category;
import org.devocean.groupbuying.domain.Compatibility;
import org.devocean.groupbuying.domain.Merchant;
import org.devocean.groupbuying.domain.Plan;
import org.devocean.groupbuying.domain.Product;
import org.devocean.groupbuying.domain.Tags;

public class MerchantBean {
	
	private Merchant merchant;
	
	private Article merchantArticle;
	
	private List<ProductBean> productsBean;
	
	
	private String mediaFilePath;
	
	private List<Tags> tags;
	
	private List<Category> categories;
	
	
	public MerchantBean(Merchant merchant) {
		
		this.merchant = merchant;
		this.productsBean = new ArrayList<ProductBean>();
		tags = new ArrayList<Tags>();
		categories = new ArrayList<Category>();
			
	}


	public Merchant getMerchant() {
		return merchant;
	}


	public void setMerchant(Merchant merchant) {
		this.merchant = merchant;
	}


	public List<ProductBean> getProductsBean() {
		
		Iterator<Product> prodIterator = this.merchant.getProducts().iterator();
		while (prodIterator.hasNext()) {
			ProductBean p = new ProductBean(prodIterator.next());
			productsBean.add(p);
		}
		return productsBean;
	}
	
	public Set<Compatibility> getCompatibilities() {
		Set<Compatibility> c = new HashSet<Compatibility>();
		for (ProductBean product : this.productsBean) {
				c.addAll(product.getCompatibilities());
		}
		return c;
	}


	public void setProductsBean(List<ProductBean> productsBean) {
		this.productsBean = productsBean;
	}


	public Article getMerchantArticle() {
		
		merchantArticle = this.merchant.getArticlesLocalization().getArticles().iterator().next();
		return merchantArticle ;
	}


	public void setMerchantArticle(Article merchantArticle) {
		this.merchantArticle = merchantArticle;
	}





	public String getMediaFilePath() {
		mediaFilePath = merchant.getArticlesLocalization().getMediaLocalizations().iterator().next().getMediaFilePath();
		return mediaFilePath;
	}


	public void setMediaFilePath(String mediaFilePath) {
		this.mediaFilePath = mediaFilePath;
	}


	public List<Tags> getTags() {
		tags.addAll(merchant.getArticlesLocalization().getTags());
		return tags;
	}


	public void setTags(List<Tags> tags) {
		this.tags = tags;
	}


	public List<Category> getCategories() {
		categories.addAll(merchant.getArticlesLocalization().getCategoriesLocalizations().iterator().next().getCategories()); 
		return categories;
	}


	public void setCategories(List<Category> categories) {
		this.categories = categories;
	}

	

}
